package com.example.work3;

import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.example.work3.QQSave.Save;

import java.util.Map;

public class zhuce_two extends AppCompatActivity implements View.OnClickListener {



    private Button btZhuce;
    private EditText ediZhucePsw;
    private EditText ediZhuceName;
    private TextView textView8;
    private String name_cunchu;
    private String psw_cunchu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuce_two);
        initView();

        Map<String,String> userInfo = Save.getUserInfo(this);
        if (userInfo != null){
            ediZhuceName.setText(userInfo.get("account"));
            ediZhucePsw.setText(userInfo.get("password"));
        }
    }

    public void onClick(View v){
        switch (v.getId()){
            case R.id.bt_zhuce:
                String account = ediZhuceName.getText().toString().trim();
                String password = ediZhucePsw.getText().toString();
                if (TextUtils.isEmpty(account)){
                    Toast.makeText(this,"请输入账号",Toast.LENGTH_SHORT).show();
                    return;
                }if (TextUtils.isEmpty(password)){
                Toast.makeText(this,"请输入密码",Toast.LENGTH_SHORT).show();
                return;
            }Toast.makeText(this,"注册成功",Toast.LENGTH_SHORT).show();
                //保存用户信息
                boolean isSaveSuccess = Save.saveUserInfo(this,account,password);
                if (isSaveSuccess){
                    Toast.makeText(this,"注册成功",Toast.LENGTH_SHORT).show();
                }else {
                    Toast.makeText(this,"注册失败",Toast.LENGTH_SHORT).show();
                }

                zhuce_two.this.finish();
                break;
        }
    }








//    public void onClick(View v) {
//        btZhuce.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                name_cunchu = ediZhuceName.getText().toString().trim();
//
//
//                SharedPreferences sp2 = getSharedPreferences("data_neam.text", Context.MODE_PRIVATE);
//                SharedPreferences.Editor editor = sp2.edit();
//                editor.putString("name",name_cunchu);
//                Log.i("123456789", name_cunchu);
//                editor.commit();
//                //声明对话框对象
//                if (name_cunchu ==null){
//                    AlertDialog.Builder builder = new AlertDialog.Builder(zhuce_Activity.this);
//                    builder.setTitle("提示");
//                    builder.setMessage("账号或密码非法，请重新填写！");
//                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                        }
//                    });
//                }else {
//                    AlertDialog.Builder builder2 = new AlertDialog.Builder(zhuce_Activity.this);
//                    builder2.setTitle("提示");
//                    builder2.setMessage("您已注册完成是否确定退出页面？");
//                    builder2.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                            zhuce_Activity.this.finish();
//                        }
//                    });
//                }
//            }
//        });
//
//
//    }


    private void initView() {

        btZhuce = (Button) findViewById(R.id.bt_zhuce);
        ediZhucePsw = (EditText) findViewById(R.id.edi_zhuce_psw);
        ediZhuceName = (EditText) findViewById(R.id.edi_zhuce_name);
        textView8 = (TextView) findViewById(R.id.textView8);
    }
}